lib/deploy: Throw an error if trying to stage when not ostree-booted
authorColin Walters <walters@verbum.org>
Tue, 1 May 2018 20:36:03 +0000 (16:36 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 2 May 2018 13:27:01 +0000 (13:27 +0000)
There's no reason to do this.  I didn't actually hit this problem,
but it's a corner case that just occurred to me while working on
the code.

I think callers should be adapted to skip trying to use staging
if there's no booted deployment.

Closes: #1568
Approved by: jlebon

src/libostree/ostree-sysroot-deploy.c
tests/admin-test.sh

index ea9dcb29ca8b73d301a2b665eb87e4bf1768fd4f..6f6181d794064b14fb15d3d323b25ee71beaf0a3 100644 (file)
@@ -2658,6 +2658,10 @@ ostree_sysroot_stage_tree (OstreeSysroot     *self,
                            GCancellable      *cancellable,
                            GError           **error)
 {
+  OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (self);
+  if (booted_deployment == NULL)
+    return glnx_throw (error, "Cannot stage a deployment when not currently booted into an OSTree system");
+
   /* This is a bit of a hack.  When adding a new service we have to end up getting
    * into the presets for downstream distros; see e.g. https://src.fedoraproject.org/rpms/ostree/pull-request/7
    *
index 6e3fd782d43cb6a358fa897568293be6c198be8b..dd87cd110ca9e296ab83a3c1905f795604c7ac56 100644 (file)
@@ -21,7 +21,7 @@
 
 set -euo pipefail
 
-echo "1..$((23 + ${extra_admin_tests:-0}))"
+echo "1..$((24 + ${extra_admin_tests:-0}))"
 
 function validate_bootloader() {
     cd ${test_tmpdir};
@@ -78,6 +78,12 @@ assert_ostree_deployment_refs 1/1/0
 ${CMD_PREFIX} ostree admin status
 echo "ok layout"
 
+if ${CMD_PREFIX} ostree admin deploy --stage --os=testos testos:testos/buildmaster/x86_64-runtime 2>err.txt; then
+    fatal "staged when not booted"
+fi
+assert_file_has_content_literal err.txt "Cannot stage a deployment when not currently booted into an OSTree system"
+echo "ok staging does not work when not booted"
+
 orig_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)
 ${CMD_PREFIX} ostree admin deploy --os=testos testos:testos/buildmaster/x86_64-runtime
 new_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)